package com.baizhi.controller;


import com.baizhi.entity.Attr;
import com.baizhi.service.IAttrService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品属性 前端控制器
 * </p>
 *
 * @author haiyu
 * @since 2021-09-16
 */
@RestController
@RequestMapping("/attr")
public class AttrController {
    @Autowired
    private IAttrService as;
    //根据商品类别的编号查看该类别下面所有的商品属性
    @GetMapping("/selectById/{cateId}")
    public List<Attr> selelectById(@PathVariable("cateId")Integer cateId){
        QueryWrapper<Attr> wrapper = new QueryWrapper<>();
        wrapper.eq("category_id",cateId);
        List<Attr> list = as.list(wrapper);
        return  list;
    }

    @GetMapping("/selectSpuById/{cateId}")
    public List<Attr> selectSpuById(@PathVariable("cateId") Integer cateId){
        QueryWrapper<Attr> wrapper = new QueryWrapper<>();
        wrapper.eq("category_id",cateId).eq("attr_type",0);
        List<Attr> list = as.list(wrapper);
        return  list;
    }
}

